package com.txts.road.app.user.controller;

import com.txts.road.app.user.model.dto.ForgetPasswordDTO;
import com.txts.road.app.user.model.dto.SmsLoginDTO;
import com.txts.road.app.user.model.dto.UserDTO;
import com.txts.road.app.user.model.dto.UserRegisterDTO;
import com.txts.road.app.user.model.vo.UserStatisticsVO;
import com.txts.road.app.user.service.UserService;
import com.txts.base.common.domain.ResponseDTO;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.txts.road.app.user.model.vo.UserVO;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import jakarta.validation.Valid;


/**
 * 用户前端控制层
 *
 * @author baoyr
 * @since 2025-07-17 10:43
 */
@Tag(name = "用户接口")
@RestController
@RequestMapping("/api/v1/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    /**
     * 用户注册
     */
    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public ResponseDTO<Boolean> register(@Valid @RequestBody UserRegisterDTO registerDTO) {
        return ResponseDTO.ok(userService.register(registerDTO));
    }

    /**
     * 手机验证码登录
     */
    @Operation(summary = "手机验证码登录")
    @PostMapping("/login/sms")
    public ResponseDTO<Boolean> loginBySms(@Valid @RequestBody SmsLoginDTO loginDTO) {
        return ResponseDTO.ok(userService.loginBySms(loginDTO));
    }


    /**
     * 忘记密码
     */
    @Operation(summary = "忘记密码")
    @PostMapping("/password/forget")
    public ResponseDTO<Boolean> forgetPassword(@Valid @RequestBody ForgetPasswordDTO forgetDTO) {
        return ResponseDTO.ok(userService.forgetPassword(forgetDTO));
    }

    /**
     * 获取用户信息
     */
    @Operation(summary = "获取用户信息")
    @GetMapping("/info")
    public ResponseDTO<UserVO> getUserInfo() {
        return ResponseDTO.ok(userService.getUserInfo());
    }

    /**
     * 更新用户信息
     */
    @Operation(summary = "更新用户信息")
    @PutMapping("/info")
    public ResponseDTO<Boolean> updateUserInfo(@Valid @RequestBody UserDTO updateDTO) {
        return ResponseDTO.ok(userService.updateUserInfo(updateDTO));
    }

    /**
     * 上传头像
     */
    @Operation(summary = "上传头像")
    @PostMapping("/avatar/upload")
    public ResponseDTO<String> uploadAvatar(@RequestParam("file") MultipartFile file) {
        return ResponseDTO.ok(userService.uploadAvatar(file));
    }

    /**
     * 获取用户统计数据
     */
    @Operation(summary = "获取用户统计数据")
    @GetMapping("/statistics")
    public ResponseDTO<UserStatisticsVO> getUserStatistics() {
        return ResponseDTO.ok(userService.getUserStatistics());
    }


}
